﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.Fashionzoomer.BLL;
using Pheonix.CodeLibrary.Web;
using Pheonix.CodeLibrary;
using Pheonix.Fashionzoomer.DAL;
using Pheonix.Fashionzoomer.Entity.SqlServer2000;

public partial class page_public_productlist : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = SiteName + " - Product Search";

        string keywords = SessionManager.SearchKeyword;
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        LoadData();
    }

    public string MaleOrFemale(object maleFemale)
    {
        if ((bool)maleFemale == true)
            return "Mens";
        else
            return "Womens";
    }

    private void LoadData()
    {
        int CurrentPage = dataPager.CurrentPage;
        //string minPrice, maxPrice, keywords, category, brand, searchType, maleFemale;

        //minPrice = Request["minPrice"];
        //maxPrice = Request.QueryString["maxPrice"];
        //keywords = Request.QueryString["keywords"];
        //category = Request.QueryString["category"];
        //brand = Request.QueryString["brand"];
        //searchType = Request.QueryString["searchType"];
        //maleFemale = Request.QueryString["maleFemale"];

        //decimal minPriceValue = (String.IsNullOrEmpty(minPrice)) ? (Decimal.MinValue) : (Decimal.Parse(minPrice));
        //decimal maxPriceValue = (String.IsNullOrEmpty(maxPrice)) ? (Decimal.MaxValue) : (Decimal.Parse(maxPrice));
        //int brandValue = (String.IsNullOrEmpty(brand)) ? (0) : (Int32.Parse(brand));
        //int categoryValue = (String.IsNullOrEmpty(category)) ? (0) : (Int32.Parse(category));
        //bool maleFemaleValue = (String.IsNullOrEmpty(maleFemale)) ? (true) : (Boolean.Parse(maleFemale));

        //string keywordsValue = (String.IsNullOrEmpty(keywords)) ? (String.Empty) : (keywords.Replace(" ", ","));
        //SearchType searchTypeValue = (String.IsNullOrEmpty(searchType)) ? (SearchType.ProductSearch) : ((SearchType)(Int32.Parse(searchType)));

        DataTable products = null;

        if (Request.QueryString["id"] != null && Request.QueryString["shopid"] != null)
        {
            int categoryId = 0;
            int shopId = 0;
            if (int.TryParse(Request.QueryString["id"], out categoryId) && int.TryParse(Request.QueryString["shopid"], out shopId))
            {
                products = CustomCommand.GetProductsByCategoryIdAndShopId(categoryId, shopId);
            }
        }
        else if (Request.QueryString["id"] != null)
        {
            int categoryId = 0;
            if (int.TryParse(Request.QueryString["id"], out categoryId))
            {
                products = CustomCommand.GetProductsByCategoryId(categoryId);
            }
        }
        else
        {
            products = CustomCommand.GetActiveProducts();
        }

        if (products != null)
        {
            PagedDataSource pagedDataSource = new PagedDataSource();
            pagedDataSource.AllowPaging = true;
            pagedDataSource.DataSource = products.DefaultView;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = CurrentPage - 1;

            dataPager.PrevPageEnabled = !pagedDataSource.IsFirstPage;
            dataPager.NextPageEnabled = !pagedDataSource.IsLastPage;

            dataPager.LastPage = pagedDataSource.PageCount;
            //if (!IsPostBack)
            //{         
            dataPager.SetPageLinks();
            //}

            productList.DataSource = pagedDataSource;
            productList.DataBind();
        }

        //if (searchTypeValue == SearchType.ProductSearch)
        //    searchResult = ProductManager.SearchProduct(minPriceValue, maxPriceValue, maleFemaleValue, keywordsValue);
        //else if (searchTypeValue == SearchType.ProductByShopSearch)
        //    searchResult = ProductManager.SearchProductByShop(minPriceValue, maxPriceValue, brandValue,
        //        maleFemaleValue, keywordsValue);
        //else if (searchTypeValue == SearchType.ProductByCategorySearch)
        //    searchResult = ProductManager.SearchProductByCategory(minPriceValue, maxPriceValue, categoryValue,
        //        maleFemaleValue, keywordsValue);
        //else
        //    searchResult = ProductManager.SearchProduct(minPriceValue, maxPriceValue, maleFemaleValue, keywordsValue);
    }
}
